package com.base.cn.platform.os.entity.classes.topic.reply;

import com.base.cn.platform.os.common.annotation.ImgAttr;
import com.base.cn.platform.os.common.mybatis.BaseEntity;
import com.base.cn.platform.os.common.utils.DataUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.*;

/**
 * 班级话题回复
 *
 * @author SK
 * @since 2018-05-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ClassesTopicReply extends BaseEntity {

    // 话题id
    private BigDecimal topicId;
    // 前台用户id
    private BigDecimal userId;
    // 评论内容
    @ImgAttr
    private String content;
    // 回复的目标评论的id
    private BigDecimal targetId;
    // 评论下的前N条评论
    private String leafIds;
    // 根评论id
    private BigDecimal rootId;
    // 子评论数量
    private Integer leafCount;
    // 点赞数
    private Integer likeCount;

    //目标评论用户
    private Map<String,Object> targetUser;
    //子评论的列表
    private List<ClassesTopicReply> leafList;
    //评论的用户
    private Map<String, Object> user;
    //
    private String userIds;

    public String getUserIds() {
        return DataUtil.filterNotNumberStr(userIds);
    }

    public void addLeaf(ClassesTopicReply leaf) {
        if (Objects.isNull(leafList)) {
            leafList = new LinkedList<>();
        }
        if (Objects.nonNull(leaf)) {
            leafList.add(leaf);
        }
    }

    public void addLeaf(Collection<ClassesTopicReply> leaf) {
        if (Objects.isNull(leafList)) {
            leafList = new LinkedList<>();
        }
        leafList.addAll(leaf);
    }
}
